﻿using System;
using Loki.IoC;

namespace Loki.Utils
{
    /// <summary>
    /// Base class.
    /// </summary>
    /// <remarks>Provides log and error management methods.</remarks>
    public abstract class LokiContextObject : LokiObject, IContextAware
    {
        #region Context injection

        public IObjectCreator Context
        {
            get;
            private set;
        }

        #region ContextInitialized

        public event EventHandler ContextInitialized;

        protected virtual void OnContextInitialized(EventArgs e)
        {
            EventHandler handler = ContextInitialized;

            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion ContextInitialized

        #endregion Context injection

        public void SetContext(IObjectContext context)
        {
            Context = context;
            OnContextInitialized(EventArgs.Empty);
        }
    }
}